package cn.jekun.shop.common.service;

import java.io.File;

import javax.annotation.Resource;

import cn.jekun.component.base.bean.SessionUser;
import cn.jekun.component.base.exceptions.TimeoutException;
import cn.jekun.component.core.action.ComponentCoreAction;
import cn.jekun.component.core.service.LogService;
import cn.jekun.shop.web.bean.MemberSession;
/**
 * action层基类
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class ShopBaseAction extends ComponentCoreAction{
	
	// myFile属性用来封装上传的文件
	public File[] myFile;
	// myFileContentType属性用来封装上传文件的类型
	public String[] myFileContentType;
	// myFileFileName属性用来封装上传文件的文件名
	public String[] myFileFileName;
	public File[] getMyFile() {
		return myFile;
	}
	public void setMyFile(File[] myFile) {
		this.myFile = myFile;
	}
	public String[] getMyFileContentType() {
		return myFileContentType;
	}
	public void setMyFileContentType(String[] myFileContentType) {
		this.myFileContentType = myFileContentType;
	}
	public String[] getMyFileFileName() {
		return myFileFileName;
	}
	public void setMyFileFileName(String[] myFileFileName) {
		this.myFileFileName = myFileFileName;
	}
	
	@Resource(name=LogService.BEAN_NAME)
	protected  LogService logService;
	
	@Override
	protected void validateTimeout() throws TimeoutException {
//		if (this.getSessionUser() == null) {
//			throw new TimeoutException("超时退出，请重新登录");
//		}

	}
	/**
	 * 获取当前登录的用户
	 * 
	 * @return
	 */
	@Override
	protected MemberSession getSessionUser() {
		return (MemberSession) this.request.getSession().getAttribute(
				SessionUser.SESSION_KEY);
	}
	/**
	 * 是否登录
	 * @return
	 */
	protected boolean isLogin(){
		return isLoginWeb();
		
	}
	
	protected String timeout() {
		return timeoutWeb();
	}
	
	/**
	 * 获取当前登录的用户
	 * @return
	 */
	@Override
	public String getUserId(){
		MemberSession memberSession = this.getSessionUser();
		if (memberSession == null) {
			return null;
		}
		return memberSession.getUserId();
	}
}
